package cn.dgfy.ssm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.dgfy.ssm.dto.UserDto;
import cn.dgfy.ssm.service.UserService;
import cn.dgfy.ssm.util.DateTimeHelper;

@Controller
@RequestMapping(value="user")
public class UserController {
	
	@Autowired
	private UserService userService;
	
	@ResponseBody
	@RequestMapping(value="get")
	public String get(long id) {
		UserDto user = userService.getUserById(id);
		
		StringBuilder result = new StringBuilder();
		
		result.append("<html><head><title>Get User Result</title></head><body>");
		
		if (user != null) {
			result.append("ID : " + user.getId());
			result.append("<br>");
			result.append("Username : " + user.getUsername());
			result.append("<br>");
			result.append("LastDate : " + DateTimeHelper.getStringFromDate(user.getLastDate()));
			result.append("<br>");
			result.append("Last IP : " + user.getLastIP());
			result.append("<br>");
		}
		
		result.append("</body></html>");
		
		return result.toString();
	}
}
